"""
AI功能相关的API数据模型
"""
from typing import Optional, List
from datetime import datetime
from pydantic import BaseModel, Field


class ChatRequest(BaseModel):
    """AI对话请求模型"""
    question: str = Field(..., min_length=1, max_length=1000, description="用户问题")
    context_limit: Optional[int] = Field(5, ge=1, le=20, description="上下文日记数量限制")


class ChatResponse(BaseModel):
    """AI对话响应模型"""
    answer: str = Field(..., description="AI回答")
    related_diaries: List[dict] = Field(default_factory=list, description="相关日记片段")
    tokens_used: int = Field(0, description="消耗的token数")
    conversation_id: int = Field(..., description="对话记录ID")


class EmotionAnalysis(BaseModel):
    """情感分析结果"""
    emotion: str = Field(..., description="主要情绪")
    confidence: float = Field(..., ge=0, le=1, description="置信度")
    mood_score: float = Field(..., ge=-1, le=1, description="情绪评分")
    emotions_detail: dict = Field(default_factory=dict, description="详细情绪分析")


class PersonalInsight(BaseModel):
    """个人洞察模型"""
    total_diaries: int = Field(0, description="日记总数")
    total_words: int = Field(0, description="总字数")
    average_mood: Optional[float] = Field(None, description="平均情绪")
    most_common_tags: List[str] = Field(default_factory=list, description="常用标签")
    writing_frequency: dict = Field(default_factory=dict, description="写作频率分析")
    mood_trend: List[dict] = Field(default_factory=list, description="情绪趋势")
    generated_at: datetime = Field(default_factory=datetime.now, description="生成时间")


class InspirationRequest(BaseModel):
    """灵感请求模型"""
    current_content: Optional[str] = Field(None, description="当前正在写的内容")
    topic: Optional[str] = Field(None, description="希望的主题方向")
    mood: Optional[str] = Field(None, description="当前心情")


class InspirationResponse(BaseModel):
    """灵感响应模型"""
    suggestions: List[str] = Field(default_factory=list, description="写作建议")
    topics: List[str] = Field(default_factory=list, description="推荐话题")
    related_memories: List[dict] = Field(default_factory=list, description="相关回忆片段")